package ModelLayer;
import java.util.ArrayList;

/**
 * Write a description of class DVD here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class DVD
{
    // instance variables - replace the example below with your own
    private int ID;
    private String title;
    private String publisher;
    private String releaseYear;
    private ArrayList<Copy> c;

    /**
     * Constructor for objects of class DVD
     */
    public DVD(int ID, String title, String publisher, String releaseYear)
    {
        this.ID = ID;
        this.title = title;
        this.publisher = publisher;
        this.releaseYear = releaseYear;
    }

    /**
     * Get methods that returns the wanted values 
     * @return     the values
     */
    public int getID()
    {
        // put your code here
        return ID;
    }

    public String getTitle()
    {
        return title;
    }

    public String getPublisher()
    {
        return publisher;
    }

    public String getReleaseYear()
    {
        return releaseYear;
    }

    /**
     * this method adds copy c to the arraylist
     * @param  Copy c
     */
    public void addCopy(Copy c)
    {
        this.c.add(c);
    }

    /**
     * this method update the copys informations
     * @param id, title, publisher, releaseYear
     */
    public void updateDVD(int ID, String title, String publisher, String releaseYear)
    {
        this.ID = ID;
        this.title = title;
        this.publisher = publisher;
        this.releaseYear = releaseYear;
    }

    /**
     * this method makes it possible to search for a copy in the list
     * @param serialNo
     */
    public Copy findCopy(String serialNo)
    {
        int index = 0;
        while(c.size() > index)
        {
            Copy copys = c.get(index);
            if(copys.getSerialNo().contains(serialNo))
            {
                return copys;
            }
            index++;
        }
        return null;
    }

    /**
     * this method returns the copy that has been searched for
     * @param serial No
     * @return c
     */
    public Copy readCopy(String serialNo)
    {
        Copy c = findCopy(serialNo);
        return c;
    }

    /**
     * this method makes it possible to update a copy
     * @param serialNo, purchaseDate, purchasePrice
     */
    public void updateCopy(String serialNo, int purchaseDate, double purchasePrice)
    {
        findCopy(serialNo).updateCopy(serialNo, purchaseDate, purchasePrice);
    }

    /**
     * this method removes a copy from the list
     * @param c
     */
    public void deleteCopy(Copy c)
    {
        this.c.remove(c);
    }

    /**
     * this method creates a Copy objekt and adds it to the list
     * @param serialNo, purcahseDate, purchasePrice
     */
    public void createCopy(String serialNo, int purchaseDate, double purchasePrice)
    {
        //Get input for Copy and send it to dvdCtr
        Copy c = new Copy(serialNo, purchaseDate, purchasePrice);
        this.c.add(c);
    }

    /**
     * this method returns the number of copies of the DVD
     * @return NoOfCopies
     */
    public int getNoOfCopies()
    {
        //Get no of copies of current DVD
        int noOfCopies = c.size();
        return noOfCopies;
    }
}
